<?php
class Faculty_Member_Permission_Model extends CI_Model {
    //exp_fmis_member_permissions


	public function __construct(){
		parent::__construct();
	}

    public function getAll()
    {
        $sql = "SELECT * FROM exp_fmis_member_permissions";
        $query =  $this->db->query($sql);
        $result = $query->result_array();
        return $result;
    }

    public function getById($id = 0)
    {
        $sql = "SELECT * FROM exp_fmis_member_permissions WHERE ID LIKE ?";
        $query =  $this->db->query($sql, $id);
        $result = $query->row_array();
        return $result;
    }

    public function getAllByMemberID($memberID)
    {
        $sql = "SELECT * FROM exp_fmis_member_permissions WHERE MemberID LIKE ?";
        $query =  $this->db->query($sql, $memberID);
        $result = $query->result_array();
        return $result;
    }

    public function getByMemberIDPermissionID($memberID, $permissionID)
    {
        $sql = "SELECT * FROM exp_fmis_member_permissions WHERE MemberID LIKE ? AND PermissionID LIKE ?";
        $query =  $this->db->query($sql, array($memberID, $permissionID));
        $result = $query->row_array();
        return $result;
    }

    public function insert($memberID, $permissionID)
    {
        $duplicate = $this->getByMemberIDPermissionID($memberID, $permissionID);

        if(!empty($duplicate))
            return false;

        $sql = "INSERT INTO exp_fmis_member_permissions (MemberID, PermissionID)
        VALUES (?, ?) ";
        $query =  $this->db->query($sql, array($memberID, $permissionID));
        return true;
    }

    public function delete($memberID, $permissionID)
    {
        $duplicate = $this->getByMemberIDPermissionID($memberID, $permissionID);

        if(empty($duplicate))
            return false;

        $sql = "DELETE FROM exp_fmis_member_permissions WHERE ID LIKE ?";
        $this->db->query($sql, $duplicate['ID']);
        return true;
    }


}
